<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
#div_body {
	text-align: left;
	vertical-align: middle;
	margin: 0px auto;
	padding: 0px;
	width: 60%;
	word-wrap:break-word;
	background-color: #ffffff;
}
</style>

<script type="text/javascript" language="javascript">
function tolow(){
	{% if tolow %}
		window.scrollTo(2000,2000);
	{% endif %}
}

function join(id){
	var postStr = "id="+id;
	var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			if (xmlhttp.responseText.indexOf('参加成功') > -1){
				document.getElementById("div_join").innerHTML="<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>&times;</button><strong>报名成功！</strong></div>";
			}else	if(xmlhttp.responseText.indexOf('已经参加') > -1){
				document.getElementById("div_join").innerHTML="<div class='alert'><button type='button' class='close' data-dismiss='alert'>&times;</button><strong>已经报名了，无需再次报名！</strong></div>";
			}else	if(xmlhttp.responseText.indexOf('出问题') > -1){
				document.getElementById("div_join").innerHTML="<div class='alert alert-error'><button type='button' class='close' data-dismiss='alert'>&times;</button><strong>出错了，返回再试试！</strong></div>";
			}else{
				document.getElementById("div_join").innerHTML="未知错误！";
			}
		}
	}
    xmlhttp.open("POST", "/join", true);  
    xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");  
    xmlhttp.send(postStr);  
}
</script>
<title>{{ obj.title }}</title>
</head>
{% include 'menu.html' %}
<div id="div_body">
<body onload="tolow()">
{% if page == 1 %}
	<h1>{{ obj.title }}</h1>
    <h4><pre>{{ obj.body }}</pre></h4>
	{% if obj.username.username == username %}
		{{ username }}
	{% else %}
		<abbr title="send message to me"><a href="/new_message/{{ user }}">{{ obj.username.username }}</a></abbr>
	{% endif %}
    <p class="text-info">{{ obj.date }}</p>
{% endif %}

{% if canjoin %}
	<div id="div_join">
		{% if username %}
			{% if joined %}
            	<div class="alert alert-success">
                	<button type="button" class="close" data-dismiss="alert">&times;</button>
					<strong>您已于 {{ datetime }}报名了!</strong>
                </div>
			{% else %}
				<a href="javascript:void(0);" onclick="return join({{ t_id }});" class="btn btn-success">我要参加</a><br>
			{% endif %}
		{% else %}
			登陆后可参与
		{% endif %}
    </div>
{% endif %}

{% if empty %}
	还没有人回答。。。
{% else %}
    {% for relation in relations %}
        <hr>
        <pre>{{ relation.text }}</pre><br>
        {% if username == relation.username.username %}
			<small><p class="text-info">{{ relation.username }}</p></small>
        {% else %}
			<abbr title="send message to me"><p class="text-info"><a href="/new_message/{{ relation.username }}">{{ relation.username }}</a></p></abbr>
        {% endif %}
        <small><font color="#CC3366">{{ relation.date }}</font></small>
    {% endfor %}
{% endif %}
{% include 'page.html' %}
{% include 'submitform.html' %}
{% include 'tail.html' %}
</div>
</body>
</html>
